package com.ying.dogying.entity;

/**
 * Created by xingwang on 2017/8/1.
 * 返回值封装
 */
public class Response<T> {

    private static final String OK = "ok";
    private static final String ERROR = "error";
    private static final String CODE_OK = "0";
    private static final String CODE_ERROR = "-1";
    private String code;
    private String msg;
    private T data;

    private String action;

    public Response success() {
        this.code = CODE_OK;
        this.msg = OK;
        return this;
    }

    public Response success(T data) {
        this.code = CODE_OK;
        this.msg = OK;
        this.data = data;
        return this;
    }

    public Response userDefined(String code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
        return this;
    }

//    public Response userLoginDefined(ResultCode resultCode, T data){
//        this.code = String.valueOf(resultCode.getCode());
//        this.msg = resultCode.getMessage();
//        this.data = data;
//        return this;
//    }

    public Response failure() {
        this.code = CODE_ERROR;
        this.msg = ERROR;
        return this;
    }

    public Response failure(String msg) {
        this.code = CODE_ERROR;
        this.msg = msg;
        return this;
    }
    public Response httpfailure(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        return this;
    }

    public Response action(String action) {
        this.action = action;
        return this;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

}
